﻿using ConfExpert.Forms.Base;
using DevExpress.Utils;
using DevTeam;

using System;
using System.Drawing;

namespace ConfExpert.Forms.Espresso
{
    public partial class EspressoList : XForm
    {
        bool FourSeason = false;
        public EspressoList(bool FourSeason = false)
        {
            InitializeComponent();
            this.FourSeason = FourSeason;
        }

        public EspressoList()
        {
            InitializeComponent();
        }

        private void EspressoList_Load(object sender, EventArgs e)
        {
            gridView1.Init("GetEspList2", FourSeason);
            if (FourSeason)
                gridView1.MakeColumnInvisible("ProductId");
            else
                gridView1.MakeColumnInvisible("Artikel");

            //bs = new BindingSource(ds, "xEspList");
            //InitGridView(gridView1, bs);
            bool vsbl = ytk(157);

            gridView1.Columns["idx"].Visible = false;
            gridView1.AddSummary("AvailableMeters", "MetersInTransit");

            gridView1.Columns["ETA"].DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
            gridView1.Columns["ETA"].DisplayFormat.FormatString = "d"; //G

            gridView1.Columns["ETAMax"].DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
            gridView1.Columns["ETAMax"].DisplayFormat.FormatString = "d"; //G

            gridView1.Columns["En"].Caption = "Width (±%3)";
            gridView1.Columns["GrM2"].Caption = "Weight (±%3)";

            gridView1.Columns["AvailableMeters"].DisplayFormat.FormatType = DevExpress.Utils.FormatType.Custom;
            gridView1.Columns["AvailableMeters"].DisplayFormat.Format = new FormatMetre();



            gridView1.Columns["MetersInTransit"].DisplayFormat.FormatType = DevExpress.Utils.FormatType.Custom;
            gridView1.Columns["MetersInTransit"].DisplayFormat.Format = new FormatMetre();

            gridView1.Columns["En"].DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
            gridView1.Columns["En"].DisplayFormat.FormatString = "#,###.## cm'.'";

            gridView1.Columns["GrM2"].DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
            gridView1.Columns["GrM2"].DisplayFormat.FormatString = "#,###.## gr'/'m2";

            foreach (string str in "KumasSatisListe;KumasSatisGercek;KumasSatisOzelIskonto".Split(';'))
            {
                gridView1.Columns[str].DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
                gridView1.Columns[str].DisplayFormat.FormatString = "$ #,###.00";
                gridView1.Columns[str].Visible = vsbl;
            }

            gridView1.FocusedRowChanged += new DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventHandler(gridView1_FocusedRowChanged);
            gridView1.RowCellStyle += new DevExpress.XtraGrid.Views.Grid.RowCellStyleEventHandler(gridView1_RowCellStyle);
            gridView1.BestFitColumns();

            gridView1.OptionsBehavior.Editable = false;
        }

        void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            txtInfo.Caption = gridView1.GetRowCellDisplayText(e.FocusedRowHandle, "ProductId");
        }

        void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
        {
            switch (e.Column.FieldName)
            {
                case "PRO":
                case "KumasSatisListe":
                case "KumasSatisGercek":
                case "KumasSatisOzelIskonto":
                    e.Appearance.Font = new Font(AppearanceObject.DefaultFont, FontStyle.Bold);
                    break;
            }
        }

    }
}